'''
author:        Wang Chenyang <cy-wang21@mails.tsinghua.edu.cn>
date:          2024-09-23
Copyright © Department of Physics, Tsinghua University. All rights reserved

Convert markdown file to bibtex file
'''

import literature_format as lf
from ai_tools import ALL_CATEGORIES
from typing import Literal


def main(fname_prefix: str):
    ''' Convert fname_prefix.md to fname_prefix.bib '''
    all_items = lf.markdown.parse_markdown_file(
        fname_prefix + ".md"
    )

    bibstr = lf.bibtex.save_to_bibtex(all_items)

    with open(fname_prefix + ".bib", "w", encoding='utf-8') as fp:
        fp.write(bibstr)


def main_from_label(category_label: str,
                    publication: Literal['arXiv']):
    ''' Get filename by label '''
    fname = (category_label + '.'
             + (ALL_CATEGORIES[ord(category_label) - ord('A')]
                .replace('\'', '').replace(' ', '_')))
    main("data/%s/%s" % (publication, fname))


if __name__ == '__main__':
    main_from_label("T", 'arXiv')
    # main("data/read")
